<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class common2 extends MY_Controller {
    /* 来自父类
     * public $ceeconfigArray;//cee配置
     * public $userinfoArray; //用户信息
     * public $isloginArray; // 用户是否登录
     */
    //析构
    function __construct(){
        parent::__construct();
        //加载数据库
        $this->load->model('Common2_model','_model');
    }
    /* ------------------------------------------------
     * 收藏：1.用户收藏 ，2.删除收藏
     * -----------------------------------------------*/
    //用户收藏
    function AjaxUserCollected(){
    	$rs = $this->_model->usercollected();
    	echo json_encode($rs);
    	return FALSE;
    }
	//删除收藏
	function AjaxUserCollectedDel(){
	    if (empty($_GET['id'])) {
	    	echo json_encode(array('ret'=>-1));
	    	return FALSE;
	    }
	    $rs = $this->_model->usercollecteddel($_GET['id']);
	    echo json_encode($rs);
	    return FALSE;
		//echo json_encode($_GET);
	}
	/* ------------------------------------------------
	 * 任务   ：1.签到 2.关注 3.添加到面板4.每日分享5.6.用户邀请、召唤7.兑换商品
	 * -----------------------------------------------*/
	//签到
	public function AjaxQianDao(){
	    //$userinfo = $this->userinfoArray;//用户信息
	    $rs = $this->_model->qiaodao();
		echo json_encode($rs);
		return FALSE;
	}
	//关注
	public function AjaxGuanZhu(){
	    $fanQQ = $_GET['fanQQ']?$_GET['fanQQ']:783350315;//关注QQ
	    $userinfo = $this->userinfoArray;//用户信息
	    $txDataArray = json_decode($userinfo['txData'],TRUE); 
	    $rs = FALSE;
	    if($txDataArray['fanQQ']['is_fan']){//关注成功
	        $rs = $this->_model->guanzhu($fanQQ);
	    }
		//echo json_encode(array("txData"=>$txData,""));
		echo json_encode(array('rs'=>$rs,'txData'=>$userinfo['txData']));
		return FALSE;
	}
	//添加到面板
	public function AjaxAddPanelGold(){
	    $userinfo = $this->userinfoArray;//用户信息
	    $txDataArray = json_decode($userinfo['txData'],TRUE);
	    $rs['ret'] = 0;
	    if($txDataArray['isAppOnPanel']){
	        $rs = $this->_model->onpanel();
	    }
	    $rs['txData'] = $userinfo['txData'];
	    echo json_encode($rs);
	    return FALSE;
	}
	//每日分享
	public function AjaxSharedAddGold(){
	    //$userinfo = $this->userinfoArray;//用户信息
	    $rs = $this->_model->userShared();
	    echo json_encode($rs);
	    return FALSE;
	}
	//用户邀请、召唤
	public function AjaxYaoqingORZhaohuan(){
	    //yaoqing、zhaohuan
	    $rs['ret'] = 0;
	    if ($_GET['action']==="yaoqing" || $_GET['action']==="zhaohuan") {
	    	//$userinfo = $this->userinfoArray;//用户信息
	        $rs = $this->_model->yaoqingORzhaohuan($_GET['action']);
	    }
	    echo json_encode($rs);
	    return FALSE;
	}
	//7.兑换
	public function AjaxTaskExchangeGoods(){
		$rs = $this->_model->AjaxTaskExchangeGoods();
		echo json_encode($rs);
		return FALSE;
	}
	/* ------------------------------------------------
	 * 其他   ：1.统计
	 * -----------------------------------------------*/
	//1.统计
	public function AjaxStatistics(){
		//无参数
		if (empty($_GET['type'])) {
			$rs['ret'] = -1;
			$rs['msg'] = "系统繁忙，请刷新操作！";
			echo json_encode($rs);
			return false;
		}
		//正常
		$rs = $this->_model->AjaxStatistics($_GET['type']);
		echo json_encode($rs);
		return FALSE;
	}
	/* ------------------------------------------------
	 * 转盘   ：//1.获奖用户 2.抽奖结果
	 * -----------------------------------------------*/
	//1.获奖用户 
	function AjaxZhuanPanAwardUser(){
		$rs = $this->_model->AjaxZhuanPanAwardUser();
		foreach ($rs as $key=>$item){
			$rs[$key]['nickname'] = $this->replaceStartFilter($item['nickname'],1,3);
		}
		echo json_encode($rs);
		return false;
	}
	//2.抽奖结果
	function AjaxChouJiangJieGuo(){
		$step = $_GET['step']?$_GET['step']:0;
		$msg = $step==0?"还差一点点就中奖了，做任务攒人品吧！":"还差一点点就中奖了，明天记得再来哦~";
		$type = $step==0?1:0;
		echo json_encode(array('ret'=>1,'type'=>1,'prize'=>8,'msg'=>$msg));
		return false;
	}
	//1.个人用户获奖
	function AjaxUserChouJiangJieGuo(){
		echo json_encode(array("ret"=>1,"tiptype"=>0,"msg"=>"你还没有抽中的奖品，继续努力攒人品哦~"));
		return false;
	}
	//字符串替换
	function replaceStartFilter($string, $start = 0, $end = 0) {
		$count = mb_strlen($string, 'UTF-8'); //此处传入编码，建议使用utf-8。此处编码要与下面mb_substr()所使用的一致
		if (!$count) {
			return $string;
		}
		if ($end == 0) {
			$end = $count;
		}
	
		$i = 0;
		$returnString = '';
		while ($i < $count) {
			$tmpString = mb_substr($string, $i, 1, 'UTF-8'); // 与mb_strlen编码一致
			if ($start <= $i && $i < $end) {
				$returnString .= '*';
			} else {
				$returnString .= $tmpString;
			}
			$i ++;
		}
		return $returnString;
	}
	
}